package org.keyyond.ms.gateway.util;

import java.security.NoSuchAlgorithmException;

import org.keyyond.ms.core.util.Md5;

public class AppUitls {

	/**
	 * 生成6位随机字符串
	* @author allan
	* @param size 位数
	* @return 返回内容 6位随机字符串
	 */
    public static String randomStr(int size) {
        String a = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        char[] rands = new char[size];
        for (int i = 0; i < rands.length; i++)
        {
            int rand = (int) (Math.random() * a.length());
            rands[i] = a.charAt(rand);
        }
        return new String(rands);
    }

    /**
     * MD5加密方法
    * @author allan
    * @param param 待加密字符串
    * @return 返回内容 加密后的MD5字符串（全部大写）
     */
    public static String generateSign(String param)
    {
    	try {
			return Md5.getEncode(param).toUpperCase();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
    }
    
    public static void main(String[] args) {
		System.out.println(generateSign("company_key=1&flag=3&radom_str=12345A&user_id=2&company_secret=1"));
	}
}
